package com.spzx.payment.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Package: com.spzx.payment.config
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/6/3 8:44
 */
@Configuration
public class AlipayConfig {

    @Value("${alipay.alipay_url}")
    private String alipayUrl;

    @Value("${alipay.app_private_key}")
    private String appPrivateKey;

    public final static String FORMAT = "json";
    public final static String CHARSET = "utf-8";
    public final static String SIGN_TYPE = "RSA2";


    public static String return_payment_url;

    public static String notify_payment_url;

    public static String alipay_public_key;

    public static String app_id;

    @Value("${alipay.app_id}")
    public void setAppId(String appId) {
        AlipayConfig.app_id = appId;
    }

    @Value("${alipay.alipay_public_key}")
    public void setAlipayPublicKey(String alipayPublicKey) {
        AlipayConfig.alipay_public_key = alipayPublicKey;
    }

    @Value("${alipay.return_payment_url}")
    public void setReturnUrl(String returnPaymentUrl) {
        AlipayConfig.return_payment_url = returnPaymentUrl;
    }

    @Value("${alipay.notify_payment_url}")
    public void setNotifyUrl(String notifyPaymentUrl) {
        AlipayConfig.notify_payment_url = notifyPaymentUrl;
    }

    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(alipayUrl, app_id, appPrivateKey, FORMAT, CHARSET, alipay_public_key, SIGN_TYPE);
    }

}